// Package coding_round_1 day_01_stack_layer_range_tree
// @Title coding_round_1
// @Description
// @Author  == 琳琳也叫王木木 ==  2021/9/2 11:51
// @Create  2021/9/2 11:51
package coding_round_1

// LayerRangeStack  使用队列实现二叉树的层序遍历
func LayerRangeStack(root *TreeNode) []int {
	if root == nil {
		return nil
	}
	ans := make([]int, 0)
	// 第一步 把头节点入队列
	var queue = []*TreeNode{root}
	for len(queue) > 0 {
		//1.出队
		temp := queue[0]
		queue = queue[1:]
		ans = append(ans, temp.Val)
		if temp.Left != nil {
			queue = append(queue, temp.Left)
		}
		if temp.Right != nil {
			queue = append(queue, temp.Right)
		}
	}
	return ans
}
